<?php
    class DbManager{
    	
    	/*** 
    	 * $mysqli 句柄 用单例模式实现.
    	 * **/
    	static  private $_instance  = NULL;
        private static $dbhost = "localhost";
        private static $dbuser = "banxi";
        private static $dbpassword =   "271828";
        private static  $dbname = "tui";
        private static       $mysqli;
  
        
        /***
         * 单例模式实现重要一点.私有化构造函数. 对于php来说还要私有化构克隆函数
         */
       private function _construct(){ 
       		self::$_instance = self::getConnect();
       }
       private function  __clone(){  } 
       

       
       /**
        *  类方法,即静态方法,单例统一入口,.
       *  @return object 返回$mysqli句柄唯一实例.
        */
       static public function getInstance(){
       		if(is_null(self::$_instance)){
       				self::$_instance = new self();
       		    }
       		    return  self::$_instance;
       	
       }
       
       
       /**
        * 
        * 连接数据库的设置.
        */
      private function getConnect(){
            $mysqli = new mysqli(self::$dbhost,self::$dbuser,self::$dbpassword,self::dbname) 
                      or die("Can not connect to the database        because:".mysqli_connect_error());
            //设置返回数据的字符编码!
            if (!$mysqli->set_charset("utf8")) {
            printf("加载字符编码失败!Error loading character set utf8: %s\n", $mysqli->error);
            }else{
                    ;//negnect
                  //printf("Current character set: %s\n", $mysqli->character_set_name());
            }//else

        return $mysqli;
        }//function getConnect
    }/* class */
?>